package com.easyapi.server.service.api.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.easyapi.common.enums.StatusCode;
import com.easyapi.common.exception.BizException;
import com.easyapi.dao.entity.api.ApiCenterProjectDatasource;
import com.easyapi.dao.mapper.api.ApiCenterProjectDatasourceMapper;
import com.easyapi.server.service.api.ProjectDatasourceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * @author javadadi
 */
@Service
public class ProjectDatasourceServiceImpl extends ServiceImpl<ApiCenterProjectDatasourceMapper, ApiCenterProjectDatasource> implements ProjectDatasourceService {

    @Resource
    private ApiCenterProjectDatasourceMapper projectDatasourceMapper;
    @Override
    public List<ApiCenterProjectDatasource> listByProjectId(Long projectId) {
        if (Objects.isNull(projectId) || projectId <= 0) {
            throw new BizException(StatusCode.PARAMS_ERROR);
        }
        return projectDatasourceMapper.listByProjectId(projectId);
    }
    @Override
    public ApiCenterProjectDatasource getByProjectIdAndDatasourceId(Long projectId, Long datasourceId) {
        if (Objects.isNull(projectId) || projectId <= 0 || Objects.isNull(datasourceId) || datasourceId <= 0) {
            throw new BizException(StatusCode.PARAMS_ERROR);
        }
        return projectDatasourceMapper.getByProjectIdAndDatasourceId(projectId, datasourceId);
    }
}
